﻿using System;
using SharpKit.JavaScript;

namespace XWeb.SharpKit.Razor
{
	[JsType(JsMode.Prototype)]
	public static class AreaExtensions
	{
		/*[JsMethod(OmitOptionalParameters = true)]
		public static string Execute<T>(this IAreaInfo<IRenderingArea<T>> areaInfo, T model = default(T))
		{
			var area = areaInfo.Create();
			if (JsContext.JsTypeOf(model) != JsTypes.undefined)
				area.Model = model;
			area.Execute();
			return area.Result;
		}*/

		[JsMethod(OmitOptionalParameters = true)]
		public static string Execute<T>(this Func<IRenderingArea<T>> view, T model = default(T))
		{
			var area = view();
			if (JsContext.JsTypeOf(model) != JsTypes.undefined)
				area.Model = model;
			area.Execute();
			return area.Result;
		}
	}
}
